home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / TIPS / MYEDIT.PAS < prev    next >
Pascal/Delphi Source File  |  1991-10-09  |  2KB  |  73 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Tips & Techniques Demo Program               }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program EditControl;
  10.  
  11. uses WinTypes, WinProcs, WObjects, Strings;
  12.  
  13. type
  14. TApp = object(TApplication)
  15.   procedure InitMainWindow; virtual;
  16. end;
  17.  
  18. PMyEdit = ^TMyEdit;
  19. TMyEdit = object(TEdit)
  20.   procedure WMKeyDownProc(var Message: TMessage);
  21.     virtual WM_KeyDown;
  22. end;
  23.  
  24. PMyWindow = ^TMyWindow;
  25. TMyWindow = Object(TWindow)
  26.   MyEdit: PMyEdit;
  27.   constructor Init(AParent:PWindowsObject; ATitle: PChar);
  28.   procedure SetUpWindow; virtual;
  29. end;
  30.  
  31. procedure TApp.InitMainWindow;
  32. begin
  33.   MainWindow := New(PMyWindow, Init(Nil, 'Edit Control'));
  34. end;
  35.  
  36. { This procedure will look the return key and not allow the Default
  37.   Window procedure to proccess them. }
  38. procedure TMyEdit.WMKeyDownProc(var Message: TMessage);
  39. var
  40.   Focus: THandle;
  41. begin
  42.   if Message.wParam = vk_Return then
  43.   begin
  44.     Focus := GetFocus;
  45.     MessageBox(HWindow, 'The Return Key Was Pressed','Attention', mb_Ok);
  46.     SetFocus(Focus);
  47.   end
  48.   else
  49.     DefWndProc(Message);     {process message normally}
  50. end;
  51.  
  52. constructor TMyWindow.Init(AParent:PWindowsObject; ATitle:PChar);
  53. const
  54.   Text: PChar = 'Press Return';
  55. begin
  56.   TWindow.Init(AParent, ATitle);
  57.   MyEdit := New(PMyEdit, Init(@Self, 0, Text, 20, 30, 150, 30, 40, False));
  58. end;
  59.  
  60. procedure TMyWindow.SetUpWindow;
  61. begin
  62.   TWindow.SetUpWindow;
  63.   SetFocus(MyEdit^.HWindow);
  64. end;
  65.  
  66. var
  67.   App: TApp;
  68. begin
  69.   App.Init('Editing');
  70.   App.Run;
  71.   App.Done;
  72. end.
  73.